<?php if ($cat) { ?>
    <link rel="stylesheet" href="<?= str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?= APPPATH ?>views/admin/css/jquery-ui-1.10.3.css" />
    <script src="<?= str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?= APPPATH ?>views/admin/js/jquery-ui-1.10.3.js"></script>
    <script>
        $(function() {
            $("#tabs").tabs();
        });
    </script>
    <form class="form-horizontal" action="<?= current_url() ?>" method="post" id="form-validate" >
        <div id="validation" class="row-fluid">
            <div class="span12">
                <div class="box corner-all">
                    <div class="box-header grd-white color-silver-dark corner-top">
                        <div class="header-control">
                            <a data-box="collapse"><i class="icofont-caret-up"></i></a>

                        </div>
                        <span><?= lang('label_menu_link_add') . ' ' . lang('label_menu_link_category'); ?></span>
                    </div>
                    <div class="box-body">

                        <fieldset>

                            <div class="control-group">
                                <?php for ($i = 1; $i <= (int) $cat->additional; $i++) { ?>
                                    <label class="control-label" for="type<?= $i ?>"><?= lang('label_additional_type') . ' ' . $i ?></label>
                                    <div class="controls">
                                        <?php
                                        if (isset($additionals[$i - 1])) {
                                            $type = ($additionals[$i - 1]->type) ? $additionals[$i - 1]->type : '';
                                            $code = ($additionals[$i - 1]->code) ? $additionals[$i - 1]->code : '';
                                        }
                                        ?>
                                        <select name="type[<?= $i ?>]" id="type<?= $i ?>">
                                            <option value="text" <?= (form_val("type=>$i") == 'text') ? 'selected' : ((isset($type) && $type == 'text') ? 'selected' : ''); ?>><?= lang('label_input_text') ?></option>
                                            <option value="list" <?= (form_val("type=>$i") == 'list') ? 'selected' : ((isset($type) && $type == 'list') ? 'selected' : ''); ?>><?= lang('label_input_list') ?></option>
                                            <option value="checkbox" <?= (form_val("type=>$i") == 'checkbox') ? 'selected' : ((isset($type) && $type == 'checkbox') ? 'selected' : ''); ?>><?= lang('label_input_checkbox') ?></option>
                                            <option value="textarea" <?= (form_val("type=>$i") == 'textarea') ? 'selected' : ((isset($type) && $type == 'textarea') ? 'selected' : ''); ?>><?= lang('label_input_textarea') ?></option>
                                        </select>
                                    </div>
                                    <input type="hidden" name="codez[<?= $i ?>]" value="<?= (isset($code) && $code != '') ? $code : '' ?>">
                                <?php } ?>
                            </div>

                            <div id="tabs">
                                <ul>
                                    <?php foreach ($language as $la) { ?>
                                        <li><a href="#<?= $la->code ?>"><img src="<?= str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?= APPPATH ?>views/admin/images/<?= $la->code ?>.png" alt=""></a>
                                        <?php } ?>
                                </ul>
                                <?php foreach ($language as $la) { ?>
                                    <div class="control-group" id="<?= $la->code ?>">
                                        <?php for ($i = 1; $i <= (int) $cat->additional; $i++) { ?>
                                            <?php
                                            if (isset($additionals[$i - 1])) {
                                                $title = ($additionals[$i - 1]->title) ? $additionals[$i - 1]->title : '';
                                                $title = unserialize($title);
                                            }
                                            ?>
                                            <label class="control-label" for="title_<?= $la->code . $i ?>"><?= lang('label_name') . ' ' . $i ?></label>
                                            <div class="controls">
                                                <input class="grd-white" name="title[<?= $i ?>][<?= $la->code ?>]" id="title_<?= $la->code . $i ?>" placeholder="<?= lang('label_name') ?>" value="<?= (form_val("title=>$i=>$la->code")) ? form_val("title=>$i=>$la->code") : ((isset($title[$la->code])) ? $title[$la->code] : '') ?>" type="text" />
                                            </div>
                                            <?php
                                            if (isset($additionals[$i - 1])) {
                                                $data = ($additionals[$i - 1]->data) ? $additionals[$i - 1]->data : '';
                                                $data = unserialize($data);
                                            }
                                            ?>
                                            <label class="control-label" for="data_<?= $la->code . $i ?>"><?= lang('label_additional_items') . ' ' . $i ?></label>
                                            <div class="controls">
                                                <textarea class="grd-white" name="data[<?= $i ?>][<?= $la->code ?>]" id="data_<?= $la->code . $i ?>" placeholder="<?= lang('label_additional_items') ?>"><?= (form_val("data=>$i=>$la->code")) ? form_val("data=>$i=>$la->code") : ((isset($data[$la->code])) ? $data[$la->code] : '') ?></textarea>
                                                <div style="color: red"><?= lang('label_additional_items_place') ?></div>
                                            </div>
                                            <div style="margin-bottom: 10px"></div>
                                        <?php } ?>
                                    </div>
                                <?php } ?>
                            </div>
                            <div style="margin: 15px" ></div>

                            <div class="control-group">
                                <label class="control-label" for="code"></label>
                                <div class="controls">
                                    <input class="grd-white" name="code" id="code" value="text" type="hidden" >
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary"><li class="icon-plus" style="margin-left: 5px"></li><?= lang('label_add') ?></button>
                                <button type="button" class="btn">Cancel</button>
                            </div>
                        </fieldset>


                    </div>
                </div>
            </div>
        </div>
    </form>
    <?php
} else {
    redirect('categories');
}
?>